<template>
  <div id="app">
    <k-form :model="ruleForm" :rules="rules" ref="loginForm">
      <k-form-item label="用户名" prop="name">
        <k-input v-model="ruleForm.name"> </k-input>
      </k-form-item>
      <k-form-item label="密码" prop="pwd">
        <k-input v-model="ruleForm.pwd" type="password"> </k-input>
      </k-form-item>
      <k-form-item>
        <el-button type="primary" @click="submitForm()">登录</el-button>
      </k-form-item>
    </k-form>
    {{ruleForm}}
  </div>
</template>

<script>
  import KForm from './components/Form.vue';
  import KFormItem from './components/FormItem.vue';
  import KInput from './components/Input.vue';
  export default {
    name: 'app',
    components: {
      KForm,
      KFormItem,
      KInput
    },
    data() {
      return {
        ruleForm: {
          name: "",
          pwd: ""
        },
        rules: {
          name: [{
              required: true,
              message: "请输入名称"
            },
            {
              min: 6,
              max: 10,
              message: "请输入6~10位用户名"
            }
          ],
          pwd: [{
            required: true,
            message: "请输入密码"
          }]
        }
      }
    },
    methods: {
      submitForm() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            alert("提交登录！");
          } else {
            console.log("校验失败");
            return false;
          }
        })
      }
    },
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>